package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        System.out.println("请输入你要删除的图书：");
        Scanner scanner=new Scanner(System.in);
        String name= scanner.nextLine();
        //遍历数组中是否存在要删除的书籍，有的话需要记录下标
        int index=-1;
        int currentSize=bookList.getUsedSize();
        for (int i = 0; i <currentSize ; i++) {
            Book book=bookList.getPos(i);
            if(name.equals(book.getName())){
                index=i;
                break;
            }
        }
        if(index==-1){
            System.out.println("目前没有这本书！");
        }
        for (int i = index; i <currentSize-1; i++) {
            Book book=bookList.getPos(i+1);
            bookList.setBooks(book,i);

        }

    }
}
